package com.luozongyao.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luozongyao.commonutils.R;
import com.luozongyao.eduService.entity.EduCourse;
import com.luozongyao.eduService.entity.EduTeacher;
import com.luozongyao.eduService.service.EduCourseService;
import com.luozongyao.eduService.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import net.sf.jsqlparser.statement.select.Limit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: guli_parent
 * @description:
 * @author: Zongyao Luo
 * @create: 2021-08-23 10:58
 **/

@RestController
@CrossOrigin
@RequestMapping("/eduService/teacherFront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页讲师列表")
    @GetMapping("/teacherList/{page}/{limit}")
    public R teacherPageList(@PathVariable long page,@PathVariable long limit){
        //根据分页查询
        Page<EduTeacher> pageParam = new Page<>(page,limit);
        Map<String,Object> map = teacherService.teacherPageList(pageParam);
        return R.ok().data(map);
    }
    //根据讲师Id获取讲师的课程和个人信息详情
    @GetMapping("getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable String id){
        EduTeacher teacher = teacherService.getById(id);
        //根据讲师id查询这个讲师的课程列表
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        //讲师有可能教多门课程
        List<EduCourse> courses = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courses",courses);
    }

}
